<?php

/*
 * Fresns Control Panel (Standalone)
 * Copyright (C) 2021-Present 刘鑫
 * Released under the MIT License.
 */

namespace App\Plugins\FcpApi\TweetFiles;

use App\Base\Services\BaseAdminService;
use App\Http\Center\Helper\CmdRpcHelper;
use App\Http\FresnsApi\Helpers\ApiConfigHelper;
use App\Http\FresnsCmd\FresnsCmdWords;
use App\Http\FresnsCmd\FresnsCmdWordsConfig;

class FsService extends BaseAdminService
{
    public function __construct()
    {
        $this->model = new FsModel();
        $this->resource = FsResource::class;
        $this->resourceDetail = FsResourceDetail::class;
    }

    public function common()
    {
        $common = parent::common();

        return $common;
    }

    public static function getImageSignUrlByFileIdUrl($fileId, $fileUrl)
    {
        //判断是否开启防盗链
        $imageStatus = ApiConfigHelper::getConfigByItemKey('images_url_status');
        if ($imageStatus == true) {
            if (empty($fileId)) {
                return $fileUrl;
            }
            $uuid = FsModel::where('id', $fileId)->value('uuid');
            $cmd = FresnsPluginConfig::FRESNS_CMD_ANTI_LINK_IMAGE;
            $input['fid'] = $uuid;

            $resp = CmdRpcHelper::call(FresnsPlugin::class, $cmd, $input);
            if (CmdRpcHelper::isErrorCmdResp($resp)) {
                return false;
            }

            return $resp['output']['imageConfigUrl'];
        } else {
            return $fileUrl;
        }
    }
}
